<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="../include/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Excel数据导入页面</title>
<%@ include file="../include/easyui.jsp"%>
</head>
<body class="easyui-layout" style="font-family: '微软雅黑'">
<div data-options="region:'center',split:true,border:false,title:'Excel数据导入'">
	<div style="padding:10px 0 10px 5px">
		<form id="excelForm" enctype="multipart/form-data" action="${ctx}/import/excelData/importExcel" method="post">
			<input type="text" id="tid" name="tid" class="easyui-validatebox" data-options="width:150,prompt: '主模板'"/>
			<input name="fileData" type="file" id="fileData" />
		</form>
	</div>
	<div style="text-align:left;padding:5px">
		<a href="javascript:void(0)" class="easyui-linkbutton" onclick="importExcel()">导入excel</a>
		<!--<a href="javascript:void(0)" class="easyui-linkbutton" onclick="exportExcel()">导出excel</a>-->
	</div>
</div>

<script type="text/javascript">
$('#tid').combotree({
	width:150,
	method:'GET',
	url: '${ctx}/import/mainExcelTemplate/lists',
	idField : 'id',
	textFiled : 'name',
	iconCls: 'icon',
	animate:true
});
function importExcel(){
	//得到上传文件的全路径
	var fileName = $('#fileData').val();
	//获取模板ID
	var tid = $('#tid').combobox('getValue');
	if(tid != ""){
		//进行基本校验
		if(fileName == ""){
			$.messager.alert('提示','请选择上传文件！','info');
		}else{
			//对文件格式进行校验
			var ext = /\.[^\.]+$/.exec(fileName);
			if(ext == ".xls" || ext == '.xlsx'){
				//提交表单
				document.getElementById("excelForm").action="${ctx}/import/excelData/importExcel";
				document.getElementById("excelForm").submit();
				$.messager.alert('提示','操作成功！','info');
				//$('#excelForm').form({
				//	success:function(data){
				//		$.messager.alert('提示','操作成功！','info');
				//	}
				//});
			}else{
				$.messager.alert('提示','请选择xls格式文件！','info');
				$('#fileData').val('');
			}
		}
	}else{
		$.messager.alert('提示','请选择模板！','info');
	}
}
</script>

</body>
</html>